/**
 * 
 */
package test;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

import test.exception.EncodeDecodeException;

/**
 * @author lcym
 *
 */
public class Convert {

	private Convert()
	{
		
	}
	
	/**
	 * 
	 * @param hexStr
	 * @return
	 * @throws DecoderException
	 */
	public static byte [] hexStrToByteArray(String hexStr) throws EncodeDecodeException{
		byte [] ret;
		
		try{
			ret = Hex.decodeHex(hexStr.toCharArray());
		}catch(DecoderException ex){
			throw new EncodeDecodeException(ex.getMessage());
		}
		
		return ret;
	}
	
	/**
	 * 
	 * @param byte_array
	 * @return
	 */
	public static String byteArrayToHexStr(byte [] byte_array){
		return Hex.encodeHexString(byte_array);
	}
}
